package leetcodecompetition.S101;

public class T6328 {
    public int maximumCostSubstring(String s, String chars, int[] vals) {
        int[] ints = new int[s.length()+1];
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            int d;
            if ((d = chars.indexOf(c)) == -1) {
                ints[i+1] = c - 'a' + 1+ints[i];
            } else {
                ints[i+1] = vals[d]+ints[i];
            }
        }
        int min=0;
        int max=0;
        for (int i = 0; i <s.length()+1 ; i++) {
            min=Math.min(min,ints[i]);
            max=Math.max(max,ints[i]-min);
        }
        return max;
    }
}
